<!--
  ###license-information-start###
  E-PIX - Enterprise Patient Identifier Cross-referencing
  __
  Copyright (C) 2009 - 2017 The MOSAIC Project - Institut fuer Community Medicine der
  							Universitaetsmedizin Greifswald - mosaic-projekt@uni-greifswald.de
  							concept and implementation
  							c. schack, d.langner, l. geidel
  							web client
  							a. blumentritt
  							g. weiher
  							please cite our publications
  							http://dx.doi.org/10.3414/ME14-01-0133
  							http://dx.doi.org/10.1186/s12967-015-0545-6
  __
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  ###license-information-end###
  -->
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:customs = "http://java.sun.com/jsf/composite/customs">
<!-- author: mathiasd -->
<!-- edited by: bialkem -->
<!-- edited by: weiherg -->
<h:body>
	<ui:composition template="/template/ths_templ.xhtml">

		<ui:define name="meta_tags">
			<meta http-equiv="Cache-Control"
				content="no-cache, no-store, must-revalidate" />
			<meta http-equiv="Pragma" content="no-cache" />
			<meta http-equiv="Expires" content="0" />
		</ui:define>

		<!-- method is called when page is loaded / without output  -->
		<ui:define name="start">
			<h:outputText value="#{generateBean.onStart()}" />
		</ui:define>

		<ui:define name="customLogo">
			<a href="index.xhtml"><img src="#{request.contextPath}/img/epix_logo.png" /></a>
		</ui:define>

		<ui:define name="header_title">
			<h:outputFormat value="#{msg['general.headertitle']}" />
		</ui:define>

		<ui:define name="title">
			<h:outputFormat value="#{msg['general.title']}" />
		</ui:define>

		<ui:define name="info">
			<customs:headerMenu activeIndex="4" />
		</ui:define>

		<ui:define name="content">
			
			<h:form id="main">
				
				<h:outputText  value="#{msg['request.label.mandatory']}" />			

				<h:outputText value="#{msg.identifier}" styleClass="headline" />
				<p:panel>
					<h:panelGrid columns="2" columnClasses="label,input">
						<p:outputLabel for="persontype"  value="#{msg.persontype}:"/>
						<h:panelGroup>
							<p:selectOneMenu
								value="#{generateBean.patientModel.personType}"
								requiredMessage="Selecting the person type is required"
								required="true" id="persontype" style="width:100%">
								<f:selectItem
									itemLabel="#{msg['request.label.pleaseSelectPersonType']}"
									itemValue="" />
								<f:selectItem itemLabel="#{msg['request.label.patient']}"
									itemValue="Patient" />
								<f:selectItem
									itemLabel="#{msg['request.label.healthcareProvider']}"
									itemValue="HealthcareProvider" />
								<p:ajax
									update=":main:generateButton :main:firstNameLabel :main:lastNameLabel :main:secondNameLabel 
								:main:birthdateLabel :main:sexLabel :main:streetLabel :main:cityLabel :main:zipLabel :main:stateLabel 
								:main:countryLabel :main:phoneLabel :main:emailLabel :main:birthplaceLabel :main:maidennameLabel 
								:main:nationalityLabel :main:degreeLabel"
									listener="#{generateBean.personTypeChangeListener()}" />
							</p:selectOneMenu>
							<p:message id="persontypeMessage" for="persontype" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="localIdentifier"  value="#{msg.localIdentifier}:"/>
						<h:panelGroup>
							<p:inputText id="localIdentifier" required="true"
								requiredMessage="The local identifier is required"
								value="#{generateBean.patientModel.localIdentifier}" />
							<p:message id="localIdentifierMessage" for="localIdentifier" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="localDomain"  value="#{msg.localDomain}:"/>
						<h:panelGroup>
							<p:selectOneMenu id="localDomain" required="true" style="width:100%"
								value="#{generateBean.patientModel.identifierDomain}"
								requiredMessage="Selecting the local domain is required">
								<f:selectItem
									itemLabel="#{msg['request.label.pleaseSelectLocalDomain']}"
									itemValue="" />
								<f:selectItems value="#{generateBean.formModel.localDomains}"
									var="domain" itemLabel="#{domain.name}"
									itemValue="#{domain.name}" />
								<p:ajax
									update=":main:generateButton :main:firstNameLabel :main:lastNameLabel :main:secondNameLabel 
								:main:birthdateLabel :main:sexLabel :main:streetLabel :main:cityLabel :main:zipLabel :main:stateLabel 
								:main:countryLabel :main:phoneLabel :main:emailLabel :main:birthplaceLabel :main:maidennameLabel 
								:main:nationalityLabel :main:degreeLabel" />
							</p:selectOneMenu>
							<p:message id="localDomainMessage" for="localDomain" />
						</h:panelGroup>												
					</h:panelGrid>				
				</p:panel>
							
				<h:outputText value="#{msg.person}" styleClass="headline" />
				<p:panel>
					<h:panelGrid columns="2" columnClasses="label,input">
						<p:outputLabel for="degree" id="degreeLabel"
							value="#{msg.degree}:" />
						<h:panelGroup>
							<p:inputText id="degree"
								value="#{generateBean.patientModel.degree}"
								requiredMessage="The degree is required"
								required="#{generateBean.formModel.returnValidation('degree')}" />
							<p:message id="degreeMessage" for="degree" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="lastName" id="lastNameLabel"
							value="#{msg.lastName}:" />
						<h:panelGroup>
							<p:inputText id="lastName"
								value="#{generateBean.patientModel.lastName}"
								requiredMessage="The last name is required"
								required="#{generateBean.formModel.returnValidation('lastName')}" />
							<p:message id="lastNameMessage" for="lastName" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="maidenname" id="maidennameLabel"
							value="#{msg.maidenname}:" />
						<h:panelGroup>
							<p:inputText id="maidenname"
								value="#{generateBean.patientModel.mothersmaidenname}"
								requiredMessage="The mothers maiden name is required"
								required="#{generateBean.formModel.returnValidation('maidenName')}" />
							<p:message id="maidennameMessage" for="maidenname" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="secondName" id="secondNameLabel"
							value="#{msg.secondName}:" />
						<h:panelGroup>
							<p:inputText id="secondName"
								value="#{generateBean.patientModel.secondName}"
								requiredMessage="The middle name is required"
								required="#{generateBean.formModel.returnValidation('secondName')}" />
							<p:message id="secondNameMessage" for="secondName" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="firstName" id="firstNameLabel"
							value="#{msg.firstName}" />
						<h:panelGroup>
							<p:inputText id="firstName"
								value="#{generateBean.patientModel.firstName}"
								required="#{generateBean.formModel.returnValidation('firstName')}"
								requiredMessage="The first name is required" />
							<p:message id="firstNameMessage" for="firstName" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="birthDate" id="birthdateLabel"
							value="#{msg.birthDate}#{msg.ddmmyyyy}:" />
						<h:panelGroup>
							<p:inputMask id="birthDate"
								value="#{generateBean.patientModel.birthDate}" mask="99.99.9999"
								validatorMessage="the birthdate is not valid"
								requiredMessage="The birth date is required"
								required="#{generateBean.formModel.returnValidation('birthDate')}">
								<f:converter converterId="org.icmvc.jsf.BirthdateConverter" />
								<f:attribute name="pattern" value="dd.MM.yyyy" />
							</p:inputMask>
							<p:message id="birthDateMessage" for="birthDate" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="birthplace" id="birthplaceLabel"
							value="#{msg.birthplace}:" />
						<h:panelGroup>
							<p:inputText id="birthplace"
								value="#{generateBean.patientModel.birthplace}"
								requiredMessage="The birth place is required"
								required="#{generateBean.formModel.returnValidation('birthplace')}" />
							<p:message id="birthplaceMessage" for="birthplace" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="sex" id="sexLabel" value="#{msg.gender}:" />
						<h:panelGroup>
							<p:selectOneMenu id="sex"
								value="#{generateBean.patientModel.sex}"
								required="#{generateBean.formModel.returnValidation('gender')}"
								requiredMessage="Selecting the gender is required"
								style="width: 100% !important">
								<f:selectItem
									itemLabel="#{msg['request.label.pleaseSelectGender']}"
									itemValue="" />
								<f:selectItems value="#{generateBean.genders}" var="gender"
									itemLabel="#{generateBean.getGenderLabel(gender)}"
									itemValue="#{gender}" />
							</p:selectOneMenu>
							<p:message id="sexMessage" for="sex" />
						</h:panelGroup>
						<!--************************************************************** -->
						<p:outputLabel for="nationality" id="nationalityLabel"
							value="#{msg.nationality}:" />
						<h:panelGroup>
							<p:inputText id="nationality"
								value="#{generateBean.patientModel.nationality}"
								requiredMessage="The nationality is required"
								required="#{generateBean.formModel.returnValidation('nationality')}" />
							<p:message id="nationalityMessage" for="nationality" />
						</h:panelGroup>
						<!--************************************************************** -->
					</h:panelGrid>
				</p:panel>
				<p:outputPanel>
					<h:outputText value="Values" styleClass="headline" />
					<p:panel>
						<h:dataTable id="valueTable" columnClasses="label,input" 
							value="#{generateBean.patientModel.values}" var="value"
							binding="#{valueTable}">
							<h:column>
								<ui:param name="valueKey" value="value#{valueTable.rowIndex+1}" />
								<ui:param name="valueMapping"
									value="#{generateBean.formModel.valueMapping.get(valueKey)}" />
								<h:outputText
									value="#{empty valueMapping? valueKey:valueMapping}" />
							</h:column>
							<h:column>
								<p:inputText
									value="#{generateBean.patientModel.values[valueTable.rowIndex]}" />
							</h:column>
						</h:dataTable>
					</p:panel>
				</p:outputPanel>



				<h:outputText value="#{msg.contact}" styleClass="headline" />
				<p:panel id="contact_input_panel">
					<p:fragment autoUpdate="true">
						<h:panelGrid columns="2" columnClasses="label,input">
							<p:outputLabel for="street" id="streetLabel"
								value="#{msg.street}:" />
							<h:panelGroup>
								<p:inputText id="street"
									required="#{generateBean.formModel.returnValidation('street')}"
									requiredMessage="The street is required"
									value="#{generateBean.contact.contact.street}" />
								<p:message id="streetMessage" for="street" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="zip" id="zipLabel" value="#{msg.zip}:" />
							<h:panelGroup>
								<p:inputText id="zip"
									required="#{generateBean.formModel.returnValidation('zip')}"
									requiredMessage="The postcode is required"
									value="#{generateBean.contact.contact.zipCode}" />
								<p:message id="zipMessage" for="zip" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="city" id="cityLabel" value="#{msg.city}:" />
							<h:panelGroup>
								<p:inputText id="city"
									required="#{generateBean.formModel.returnValidation('city')}"
									requiredMessage="The city is required"
									value="#{generateBean.contact.contact.city}" />
								<p:message id="cityMessage" for="city" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="district" id="districtLabel" value="#{msg.district}:" />
							<h:panelGroup>
								<p:inputText id="district"
									required="#{generateBean.formModel.returnValidation('district')}"
									requiredMessage="The district is required"
									value="#{generateBean.contact.contact.district}" />
								<p:message id="districtMessage" for="district" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="state" id="stateLabel" value="#{msg.state}:" />
							<h:panelGroup>
								<p:inputText id="state"
									required="#{generateBean.formModel.returnValidation('state')}"
									requiredMessage="The state is required"
									value="#{generateBean.contact.contact.state}" />
								<p:message id="stateMessage" for="state" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="country" id="countryLabel"
								value="#{msg.country}:" />
							<h:panelGroup>
								<p:inputText id="country"
									required="#{generateBean.formModel.returnValidation('country')}"
									requiredMessage="The country is required"
									value="#{generateBean.contact.contact.country}" />
								<p:message id="countryMessage" for="country" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="phone" id="phoneLabel" value="#{msg.phone}:" />
							<h:panelGroup>
								<p:inputText id="phone"
									required="#{generateBean.formModel.returnValidation('phone')}"
									requiredMessage="The phone number is required"
									value="#{generateBean.contact.contact.phone}" />
								<p:message id="phoneMessage" for="phone" />
							</h:panelGroup>
							<!--************************************************************** -->
							<p:outputLabel for="mail" id="emailLabel" value="#{msg.email}:" />
							<h:panelGroup>
								<p:inputText id="mail"
									required="#{generateBean.formModel.returnValidation('email')}"
									requiredMessage="The E-Mail address is required"
									value="#{generateBean.contact.contact.email}" />
								<p:message id="mailMessage" for="mail" />
							</h:panelGroup>
							<!--************************************************************** -->
							<h:outputText id="addContactButtonLabel_epmty" value="" />
							<h:panelGroup>
								<div align="right">
									<p:commandButton id="addContactButton"
										value="#{generateBean.contact.id==0?msg.addContact:msg.saveContact}"
										actionListener="#{generateBean.addContact}"
										update="@form:contacts,@form:contact_input_panel" />
									<p:commandButton rendered="#{generateBean.contact.id!=0}"
										immediate="true" update="@form:contact_input_panel"
										id="editContactCancel" value="#{msg.cancel}"
										actionListener="#{generateBean.cancelButtonListener()}">
										<p:resetInput target="@form:contact_input_panel"></p:resetInput>
									</p:commandButton>
								</div>
								<p:messages id="addContactInfo" for="info" showDetail="true"
									autoUpdate="true" severity="info" />
							</h:panelGroup>
						</h:panelGrid>
					</p:fragment>
					<h:outputText id="addContactButtonLabel_empty"
						value="#{msg.contactList}" />
					<p:dataTable id="contacts" var="contactEntry"
						value="#{generateBean.patientModel.tableContacts}"
						scrollable="false" liveScroll="false" resizableColumns="true"
						rowKey="#{contactEntry.id}" scrollRows="5" lazy="true"
						emptyMessage="#{msg.nocontacts}">

						<p:column headerText="#{msg.street}">
							<h:outputText value="#{contactEntry.contact.street}" />
						</p:column>
						<p:column headerText="#{msg.zip}">
							<h:outputText value="#{contactEntry.contact.zipCode}" />
						</p:column>
						<p:column headerText="#{msg.city}">
							<h:outputText value="#{contactEntry.contact.city}" />
						</p:column>
						<p:column headerText="#{msg.district}">
							<h:outputText value="#{contactEntry.contact.district}" />
						</p:column>
						<p:column headerText="#{msg.state}">
							<h:outputText value="#{contactEntry.contact.state}" />
						</p:column>
						<p:column headerText="#{msg.country}">
							<h:outputText value="#{contactEntry.contact.country}" />
						</p:column>
						<p:column headerText="#{msg.phone}">
							<h:outputText value="#{contactEntry.contact.phone}" />
						</p:column>
						<p:column headerText="#{msg.email}">
							<h:outputText value="#{contactEntry.contact.email}" />
						</p:column>
						<p:column headerText="#{msg.edit}/#{msg.remove}"
							style="text-align:center">
							<p:commandButton id="rowEditButton" icon="ui-icon-pencil"
								process="@form:contacts"
								actionListener="#{generateBean.editButtonListener(contactEntry)}"
								update="@form:contact_input_panel" />
							<p:commandButton id="rowDeleteButton" icon="ui-icon-closethick"
								process="@form:contacts"
								actionListener="#{generateBean.deleteButtonListener(contactEntry)}"
								update="@form:contacts">
								<p:confirm message="#{msg.contactDeleteConfirm}"
									header="Delete Contact" icon="ui-icon-alert"></p:confirm>
							</p:commandButton>
						</p:column>
					</p:dataTable>
					<p:confirmDialog global="true" showEffect="fade">
						<p:commandButton value="Yes" type="button"
							styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
						<p:commandButton value="No" type="button"
							styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
					</p:confirmDialog>
					<p:messages id="feedbackMessage" for="feedback" showDetail="true"
						autoUpdate="true" severity="info" />

				</p:panel>
				<div class="spacerH20"></div>

				<div class="alignRight">
					<p:commandButton value="#{msg.generatePerson}" id="generateButton"
						update=":main:persontypeMessage :main:localIdentifierMessage :main:localDomainMessage 
								:main:lastNameMessage :main:firstNameMessage :main:secondNameMessage :main:birthDateMessage :main:sexMessage
								:main:streetMessage :main:zipMessage :main:cityMessage :main:stateMessage :main:countryMessage 
								:main:phoneMessage :main:mailMessage :main:birthplaceMessage :main:maidennameMessage 
								:main:nationalityMessage :main:degreeMessage"
						action="#{generateBean.generateButtonListener}"
						style="font-weight: bold;" />
				</div>
				<div class="clear"></div>

			</h:form>
			<br />
		</ui:define>
		<ui:define name="version">
			<h:outputText value="${display_version}" />
		</ui:define>
	</ui:composition>
</h:body>
</html>
